//
//  NSObjectExtension.swift
//  Bocai
//
//  Created by GujyHy on 2017/11/24.
//  Copyright © 2017年 GujyHy. All rights reserved.
//

import UIKit
import SVProgressHUD

extension NSObject {
    
    // MARK: HUD
    func showSubmitHUD(maskType:SVProgressHUDMaskType){
        self.showHUD("提交中",maskType:maskType)
    }
    func showErrHUD(_ text:String){
        if text != "" {
            self.showErrorHUD(text)
        }
    }
    func showSucssHUD(_ text:String){
        self.showSuccessHUD(text)
    }
    
    fileprivate func showHUD(_ text:String,maskType:SVProgressHUDMaskType){
        SVProgressHUD.setMinimumSize(CGSize(width:AdaptedWidthValue(x: 100), height: AdaptedWidthValue(x: 100)))
        SVProgressHUD.setDefaultMaskType(maskType)
        SVProgressHUD.show(withStatus: text)
    }
    fileprivate func showSuccessHUD(_ text:String){
        SVProgressHUD.setMinimumSize(CGSize(width:AdaptedWidthValue(x: 100), height: AdaptedWidthValue(x: 100)))
        SVProgressHUD.setMinimumDismissTimeInterval(2)
        SVProgressHUD.setDefaultMaskType(.black)
        SVProgressHUD.showSuccess(withStatus: text)
    }
    
    fileprivate func showErrorHUD(_ text:String){
        SVProgressHUD.setMinimumSize(CGSize(width:AdaptedWidthValue(x: 100), height: AdaptedWidthValue(x: 100)))
        SVProgressHUD.setMinimumDismissTimeInterval(1.5)
        SVProgressHUD.setDefaultMaskType(.black)
        SVProgressHUD.showInfo(withStatus: text)
    }
    
    func dismissHUD(){
        SVProgressHUD.dismiss()
    }
}

